package com.moyq5.mvc.maker.test.bean.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

/**
 * 用户消费记录
 * @author Moyq5
 * @date 2018年4月18日
 */
@Entity
@Table(name = "uc_user_expense")
@DynamicUpdate
public class UserExpense implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 消费ID
	 */
	@Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "native")@GenericGenerator(name = "native", strategy = "native")
    @Column(name = "expense_id")
	private Long expenseId;
	/**
	 * 消费者
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "user_id")
	private User user;
	/**
	 * 设备
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "device_id")
	private IotDevice device;
	/**
	 * 门店
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "shop_id")
	private Shop shop;
	/**
	 * 商家
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "merch_id")
	private Merch merch;
	/**
	 * （总共）消费积分
	 */
	@Column(name = "total_quantity", precision = 8, nullable = false)
	private Integer totalQuantity;
	/**
	 * （商家）消费积分
	 */
	@Column(name = "merch_quantity", precision = 8, nullable = false)
	private Integer merchQuantity;
	/**
	 * （门店）消费积分
	 */
	@Column(name = "shop_quantity", precision = 8, nullable = false)
	private Integer shopQuantity;
	/**
	 * 消费时间
	 */
	@Column(name = "add_time", nullable = false, columnDefinition="datetime")
	private Date addTime;
	
	@PrePersist
	public void prePersist() {
		if (null == addTime) {
			addTime = new Date();
		}
	}
	
	public Long getExpenseId() {
		return expenseId;
	}
	public void setExpenseId(Long expenseId) {
		this.expenseId = expenseId;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public IotDevice getDevice() {
		return device;
	}
	public void setDevice(IotDevice device) {
		this.device = device;
	}
	public Shop getShop() {
		return shop;
	}
	public void setShop(Shop shop) {
		this.shop = shop;
	}
	public Merch getMerch() {
		return merch;
	}
	public void setMerch(Merch merch) {
		this.merch = merch;
	}
	public Integer getTotalQuantity() {
		return totalQuantity;
	}
	public void setTotalQuantity(Integer totalQuantity) {
		this.totalQuantity = totalQuantity;
	}
	public Integer getMerchQuantity() {
		return merchQuantity;
	}
	public void setMerchQuantity(Integer merchQuantity) {
		this.merchQuantity = merchQuantity;
	}
	public Integer getShopQuantity() {
		return shopQuantity;
	}
	public void setShopQuantity(Integer shopQuantity) {
		this.shopQuantity = shopQuantity;
	}
	public Date getAddTime() {
		return addTime;
	}
	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}
	
}
